import subprocess as subp
class Test :
	def getIfProperties(self, if_name):
		command = """
			Interfaces=`ifconfig -a """ +  if_name + """\\
				| grep -o -e "[a-z][a-z]*[0-9]*[ ]*Link" \\
				| perl -pe "s|^([a-z]*[0-9]*)[ ]*Link|\\1|"`

			for Interface in $Interfaces; do
				INET=`ifconfig $Interface | grep -o -e "inet addr:[^ ]*" | grep -o -e "[^:]*$"`
				MASK=`ifconfig $Interface | grep -o -e "Mask:[^ ]*"      | grep -o -e "[^:]*$"`
				STATUS="up"
				if [ "$INET" == "" ]; then
					INET="-"
					MASK="-"
					STATUS="down";
				fi
				printf "%s %s %s %s" "$Interface" "$INET" "$MASK" "$STATUS"
			done
		"""
		proc = subp.Popen(command,shell=True, stdout=subp.PIPE, stderr=subp.PIPE)
		proc.wait()
		print proc.stdout.readlines()
		print proc.stderr.readlines()


t = Test()
t.getIfProperties("eth0")

